package doc2jpg

import com.fiberhome.dcs_1.DocConvertParam
import com.fiberhome.dcs_1_0.Dcs
import grails.transaction.Transactional

@Transactional
class DocConvertService {

//    Dcs dcsService
    def dcsSoapClient
//    def doc2jpg(String docUrl,String docType){
//        def destDocType = 'jpg'
//        def checkKey = "${docUrl}${destDocType}dcs".encodeAsMD5()
//
//        println checkKey
//
//
//        dcsService.docConvert(docType,docUrl,destDocType,checkKey,new DocConvertParam(startPage: 1,endPage: 2,zoom: 1L,moreConvertPage: 1,docKey: ''))
//    }

    def doc2jpg(String docUrl,String docType){
        def destDocType = 'jpg'
        def checkKey = "${docUrl}${destDocType}dcs".encodeAsMD5()


        dcsSoapClient.send("""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dcs="http://www.fiberhome.com/dcs_1.0/">
   <soapenv:Header/>
   <soapenv:Body>
      <dcs:docConvert>
         <srcDocType>doc</srcDocType>
         <srcDocAddr><![CDATA[${docUrl}]]></srcDocAddr>
         <destDocType><![CDATA[${destDocType}]]></destDocType>
         <checkKey><![CDATA[${checkKey}]]></checkKey>
         <docConvertParams>
            <startPage>1</startPage>
            <endPage>2</endPage>
            <zoom>1</zoom>
            <moreConvertPage>0</moreConvertPage>
            <docKey/>
         </docConvertParams>
      </dcs:docConvert>
   </soapenv:Body>
</soapenv:Envelope>


""")

//        dcsService.docConvert(docType,docUrl,destDocType,checkKey,new DocConvertParam(startPage: 1,endPage: 2,zoom: 1L,moreConvertPage: 1,docKey: ''))
    }


}
